<html>
<!--
	This file is part of Limpet.

    Limpet is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Limpet is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Limpet.  If not, see http://www.gnu.org/licenses/.
	
	Copyright 2010 Dan Popick
-->
<head>

<style type="text/css"> 
	div, table, tr, td {
		margin: 0;
		padding: 0;
		border: 0;
		outline: 0;
		font: normal normal normal 16px/normal helvetica, verdana, tahoma, arial, 'sans serif';
		font-weight: bold;
		letter-spacing: -1px;

	}
	
	body {
	}
	
	table {
		border-collapse: collapse;
		width: 250px;
	}

	tr {
	}
	
	td {
		border: 1px solid #000;
		padding: 5px;
	}
	
	tr td:nth-child(2) {
		font-weight: normal;
		letter-spacing: 0px;
		font-size: 14px;
	}
	
	tr.fatal td:nth-child(1), 
	tr.error td:nth-child(1) {
		background: #b22; 
		color: #fff;
	}
	
	tr.warning td:nth-child(1) {
		background: #ff0; 
		color: #000;
	}
	
	tr.info td:nth-child(1) {
		background: #0f0; 
		color: #000;
	}
	
	tr.verbose td,
	tr.debug td {
		background: #a9a9a9; 
		color: #000;
	}
	
	tr.verbose td:nth-child(2), 
	tr.debug td:nth-child(2) {
		background: #ddd; 
	}
	
	div.button {
		margin-top: 6px;
		padding: 3px;
		border-radius: 6px;
		background: #a00;
		display: block;
		text-align: center;
	}
	
	a.b_link {
		color: #fff;
		text-decoration: none;
	}
	
</style>

<script>

var globalSite;

function go() {
	chrome.tabs.getSelected(null, function(tab) { 
		chrome.extension.sendRequest(
			{
				command: "getSite",
				url: tab.url,
			},
			function(site) { 
				site.data = JSON.parse(site.data);
				globalSite = site;
				showPageInformation(site.data);
			});
		}); 
}

function showPageInformation(siteData) {
	var tab = document.getElementById("tab");
	for (var i = 0; i < siteData.length; ++i) {
		var message = siteData[i];
		var row = document.createElement('tr');
		row.setAttribute("class", message.severity);
		var td = document.createElement("td");
		td.textContent = message.category;
		row.appendChild(td);
		td = document.createElement("td");
		td.textContent = message.text;
		row.appendChild(td);
		tab.appendChild(row);
	}
}

function open() {
	chrome.extension.sendRequest({ command: "openDisplay", site: globalSite });
}

document.addEventListener("load", go);

</script>
</head>
<body onload="go();">

<table id="tab">
</table>

<a href="javascript: open()" class="b_link">  
	<div class="button">
	open details
	</div>
</a>
</html>